[PATCH] v8: fix missing callback in heap utils destroy
authorRuben Bridgewater <ruben.bridgewater@datadoghq.com>
Mon, 30 Jun 2025 11:51:40 +0000 (13:51 +0200)
committerJérémy Lal <kapouer@melix.org>
Tue, 24 Mar 2026 21:11:25 +0000 (22:11 +0100)
This fixes the v8.getHeapSnapshot() calls not properly being
destroyed. Pipeline calls would for example not properly end
without the callback being in place.

PR-URL: https://github.com/nodejs/node/pull/58846
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com>
Gbp-Pq: Topic sec
Gbp-Pq: Name 19-v8-fix-missing-callback-in-heap-utils-destroy.patch

lib/internal/heap_utils.js
test/sequential/test-heapdump.js

index c39d811ab793b01d43731dcf7aff94a4cb644724..6d72fb1d628540b5c4cadd7c90edd0fccd7809f4 100644 (file)
@@ -53,11 +53,12 @@ class HeapSnapshotStream extends Readable {
       this[kHandle].readStart();
   }
 
-  _destroy() {
+  _destroy(err, callback) {
     // Release the references on the handle so that
     // it can be garbage collected.
     this[kHandle][owner_symbol] = undefined;
     this[kHandle] = undefined;
+    callback(err);
   }
 
   [kUpdateTimer]() {
index 1388623e61f939f6f84fc5f3564a273b1cd1c747..ee025f57fb82586b58c95eebf9657debcd4c64be 100644 (file)
@@ -8,6 +8,7 @@ if (!common.isMainThread)
 const { writeHeapSnapshot, getHeapSnapshot } = require('v8');
 const assert = require('assert');
 const fs = require('fs');
+const { promises: { pipeline }, PassThrough } = require('stream');
 const tmpdir = require('../common/tmpdir');
 
 tmpdir.refresh();
@@ -76,3 +77,13 @@ process.chdir(tmpdir.path);
     JSON.parse(data);
   }));
 }
+
+{
+  const passthrough = new PassThrough();
+  passthrough.on('data', common.mustCallAtLeast(1));
+
+  pipeline(
+    getHeapSnapshot(),
+    passthrough,
+  ).then(common.mustCall());
+}